<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/main.css" />
    <link rel="stylesheet" type="text/css" href="../css/login.css" />
</head>
<body style="background-image:url('../image/login.jpg');background-size:100% 100%">
  <div class="login_box">
      <h1>登录</h1>
      <div class="form-control"><input class="login_input" placeholder="请输入手机号" id="email"/></div>
      <div class="form-control"><input class="login_input" type="password" placeholder="密码" id="password"/></div>
      <div class="form-control"><button class="login_btn" onclick="login()" tapmode>登录</button></div>
      <div class="form-control"><a href="phoneLogin.html" class="href_white">手机验证码登录</a></div>
      <div class="form-control"><a href="register.html" class="href_white">没有帐号，立刻注册</a></div>
  </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/main.js"></script>
<script type="text/javascript">
apiready=function(){

}
//登录专用get
// function get_login(url,functionRet,functionErr){
//   var jwt=$api.getStorage('jwt');
//   api.ajax({
//     url: 'http://113.17.111.241:9999/universityfacade'+url,
//     method: 'GET',
//     headers: {
//       "Access-Control-Allow-Origin": "*",
//       "Access-Control-Allow-Headers": "Authorization",
//       "Authorization": "Bearer"+" "+jwt
//     }
//   }, function(ret, err) {
//     // if(err.statusCode == 401){
//     //   alert("该账号在另一台设备登录，如不是本人操作，请尽快修改密码");
//     //   $api.clearStorage();
//     //   api.rebootApp();
//     // }
//       if (ret) {
//         functionRet(ret);
//       } else {
//         functionErr(err);
//       }
//   });
// }

function login(){
  var email = $('#email').val();
  var password = $('#password').val();
  var deviceId = api.deviceId;
  //账号密码都不能为空
  if (email!=""&&password!="") {
    api.ajax({
      url: 'http://47.104.170.122/v1/portal/auth/login?accountNumber='+email+'&password='+password,
      method: 'POST',
      headers: {
        "Access-Control-Allow-Origin": "*",
        "Access-Control-Allow-Headers": "Authorization",
        "Content-Type" : 'application/json; charset=utf-8'
      }
    }, function(ret, err) {
        if (ret.code==0) {
          var jwt=ret.data;
          //获取账号信息
          api.ajax({
            url: 'http://47.104.170.122/v1/portal/auth/app/loginInfo?token='+jwt,
            method: 'GET',
            headers: {
              "Access-Control-Allow-Origin": "*",
              "Access-Control-Allow-Headers": "Authorization",
              "Content-Type" : 'application/json; charset=utf-8'
            }
          }, function(ret, err) {
            if(ret.code==0){
              toast("登陆成功","bottom");
            //存储aid和jwt
            //$api.setStorage('deviceId', deviceId);
            $api.setStorage('jwt', jwt);
            $api.setStorage('aid', ret.data.aid);
            $api.setStorage('flag', ret.data.flag);
            $api.setStorage('nickname', ret.data.nickname);
            $api.setStorage('userHeaderImageUrl', ret.data.userHeaderImageUrl);
            api.openFrame({
                        name: 'main',
                        url: 'main.html',
                        bounces: false,
                        rect: {
                            x: 0,
                            y: 0,
                            w: 'auto',
                            h: api.winHeight
                        }
                    })
                }else {
                  toast("登陆失败","bottom");
                }
          });
        } else {
          toast("登陆失败","bottom");
        }
    });
    }else {
        api.toast({
            msg: '请填写相关信息',
            duration: 2000,
            location: 'bottom'
        })
    }
}
</script>
</html>
